//
//  HykStatusCell.swift
//  sinaWeiBo
//
//  Created by hyk on 15/12/5.
//  Copyright © 2015年 hyk. All rights reserved.
//

import UIKit

class HykStatusCell: UITableViewCell {
     //MARK:属性
     //微博模型
    var status : HykStatus?{
        didSet{
          // 将模型赋值给顶部视图,顶部视图就可以显示内容
          topView.status = status
            
            // cell 微博内容
        contentLabel.text = status?.text
        }
    
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        //准备UI
        prepareUI()
    }
    
    private func  prepareUI(){
        //添加子控件
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(bottomView)
        //添加约束
        /// 顶部控件, 在contentView内部,左上没有偏移
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44))
        
        //微博文本内容的约束
        /// 微博内容在 顶部控件 左下
        contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 8, y: 8))
        //宽度
        contentView.addConstraint(NSLayoutConstraint(item: contentLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        //底部视图，在contentLabel 的左下
        bottomView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: -8, y: 8))
        
    
    }
    
    //MARK：-懒加载
    //顶部view
    private lazy var topView:HykStatusTopView = HykStatusTopView()
    
    //微博文本内容
    private lazy var contentLabel:UILabel  = {
       let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
      label.numberOfLines = 0
      return label
    }()
    
    //底部视图
    private lazy var bottomView:HykStatusBottomView = HykStatusBottomView()

}
